package com.ayic.garbagerecycle.mapper;

import com.ayic.garbagerecycle.pojo.WasteRecord;
import com.ayic.garbagerecycle.pojo.WasteRecordLite;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RecyclingMapper {

    /**
     * 获取用户今日的回收总量
     * @param userId 用户ID
     * @return 今日回收总量
     */
    @Select("SELECT COALESCE(SUM(w.value), 0) FROM waste_records w " +
            "INNER JOIN stations s ON w.station_id = s.station_id " +
            "WHERE s.user_id = #{userId} " +
            "AND DATE_FORMAT(w.created_at, '%Y-%m-%d') = DATE_FORMAT(CURRENT_DATE, '%Y-%m-%d')")
    Integer getTodayRecyclingByUserId(Integer userId);

    /**
     * 获取用户本月的回收总量
     * @param userId 用户ID
     * @return 本月回收总量
     */
    @Select("SELECT COALESCE(SUM(w.value), 0) FROM waste_records w " +
            "INNER JOIN stations s ON w.station_id = s.station_id " +
            "WHERE s.user_id = #{userId} " +
            "AND DATE_FORMAT(w.created_at, '%Y-%m') = DATE_FORMAT(CURRENT_DATE, '%Y-%m')")
    Integer getMonthRecyclingByUserId(Integer userId);

    // 用于回收统计
    @Select("SELECT  waste_type_id wasteType, weight FROM waste_records")
    List<WasteRecordLite> selectAllRecords();
}